<template>
  <div o-Container>
    <o-list v-bind:source="list.proprietor"
            v-bind="{created:create,exported:output,modified:modify,searched:search}"/>
    <o-dialog v-bind:source="panel" v-bind="{opened:load,closed:load}">
      <template slot="content">
        <o-item v-bind:source="item.proprietor" v-bind="{saved:save,backed:back,loaded:load}"></o-item>
      </template>
    </o-dialog>
  </div>
</template>

<script>
  export default {
    name: "mms_cus_proprietor_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
    data() {
      return {
        octopus: this.$parent.octopus,
        list: {
          proprietor: {
            data: {
              id: 298,
              cellData: [
                {name: "CompanyID", width: 150, searchKey: "=", filterKey: "="},// 公司
                {name: "ProjectID", width: 200, searchKey: "=", filterKey: "=", link: [{binding: "CompanyID", mapping: "CompanyID"}]},// 小区
                {name: "Code", width: 80},       // 商户编码
                {name: "UniqueCode", width: 270}, // 商户唯一编码
                {name: "CreditCode", width: 170}, // 社会信用代码
                {name: "TypeID", width: 80},     //商户类型
                {name: "Name", width: 200, searchKey: "LIKE"},//名称
                {name: "FormerName", width: 100, searchKey: "LIKE"},//名称
                {name: "LevelID", width: 100, searchKey: "="},	// LevelID
                // {name: "ContractCode", searchKey: "LIKE"},// 合同编号
                {name: "LeaseTypeID", searchKey: "="},// 租赁类型
                {name: "LeaseTypeID"},// 租赁类型
                {name: "IndustryID", searchKey: "="},//工业  id
                {name: "ContactName", width: 100},//联系名称
                {name: "ContactNumber", width: 100, searchKey: "LIKE"},//联系号码
                // {name: "ElectricityPriceID", link: [{binding: "CompanyID", mapping: "CompanyID"}]},// 电价
                {name: "Status", width: 50, searchKey: "LIKE"},//名称
                {name: "StartTime"},	// EndTime
                {name: "EndTime"},	// EndTime
                {name: "CreateTime", width: 150},//创建时间
              ],
            }
          },
        },
        item: {
          proprietor: {
            data: {
              id: 7,
              cellData: [
                {name: "ProjectID"},  //小区
                {name: "Code"},//编码
                {name: "Name"},       // 名称
                {name: "FormerName"}, // 曾用名
                {name: "UniqueCode"}, // 商户唯一编码
                {name: "CreditCode"}, // 社会信用代码
                {name: "TypeID"},     //商户类型
                {name: "LeaseTypeID"},//租售类型
                {name: "IndustryID"}, //工业类型
                {name: "Brand"},//品牌
                {name: "LevelID"},//业主级别
                // {name: "ContractCode"},//联系代码
                {name: "ContactName"},//联系名称
                {name: "ContactNumber"},//联系号码
                {name: "Status"},//名称
                {name: "StartTime"},	// EndTime
                {name: "EndTime"},	// EndTime
                // {name: "ElectricityPriceID", link: [{binding: "CompanyID", mapping: "CompanyID"}]},// 电价
                // {name: "WaterPriceID", link: [{mapping: "ProjectID", value: this.$parent.octopus.passport.project}]},// 水价
                // {name: "GasPriceID", link: [{mapping: "ProjectID", value: this.$parent.octopus.passport.project}]},// 气价
                {name: "CreateTime"},//创建时间
                {name: "Note"},//备注
              ]
            },
          },
        },
        panel: {
          visible: false,
        },
      }
    },
    created: function () {
      this.init();
    },
    methods: {
      init: function () {
        let url = this.octopus.vue.$route.path;
        // MMS
        if (url.indexOf("MMS/Project/Proprietor/List") > 0) {
          //
        }
        // MDM
        else {
          // // alert(this.octopus.passport.authorization.company);
          // this.octopus.tools.parseCell(this.list.proprietor.data, "CompanyID").show = false;
          // this.octopus.tools.parseCell(this.list.proprietor.data, "CompanyID").searchKey = null;
          // this.octopus.tools.parseCell(this.list.proprietor.data, "CompanyID").filterValue = this.octopus.passport.authorization.company;
          // this.octopus.tools.parseCell(this.list.proprietor.data, "ProjectID").show = false;
          // this.octopus.tools.parseCell(this.list.proprietor.data, "ProjectID").filterValue = this.octopus.passport.project;
          // this.octopus.tools.parseCell(this.item.proprietor.data, "ProjectID").link = [{
          //   mapping: "CompanyID",
          //   value: this.octopus.passport.authorization.company
          // }];
          // this.octopus.tools.parseCell(this.item.proprietor.data, "CompanyID").disabled = true;
          // // 配置模式下 只能选择当前项目下的租户/业主。
          // this.octopus.tools.parseCell(this.item.berth.data, "ProprietorID").link = [{mapping: "ProjectID", value: this.octopus.passport.project}];
        }
      },
      create: function () {//新增
        this.item.proprietor.data.value = null;
        this.item.proprietor.control.load();
        this.panel.visible = true;
      },
      output: function (data) {//导出excel报表
        this.octopus.tips.success('下载完成。');
        // 导出以后，回调这里给客户端操作。
        // 核心思想是cellData包含search数据（不管有没有），回传以后发送export指令，后台api会直接返回导出的数据提供下载。
      },
      search: function (cell) {
        // 。
      },
      modify: function (row) {//修改
        this.item.proprietor.data.value = row.ID;
        this.item.proprietor.control.load();
        this.panel.visible = true;
      },
      load: function (data) {//加载数据
        // 只有创建时，才设置默认值。
        if (this.octopus.tools.IsNullOrEmpty(data.content.value)) {
          // this.octopus.tools.parseCell(this.item.proprietor.data, "CompanyID").defaultValue = this.octopus.passport.authorization.company.toString();
        }
      },
      save: function (data) {//保存
        this.octopus.tips.success(data);
        this.list.proprietor.control.load();// 刷新list
        this.back();
      },
      back: function () {//返回 模态框消失
        this.panel.visible = false;
      }
    },
    props: ["oData"]
  }
</script>
